#coding=utf-8
import re
from typing import Pattern
import requests
from requests.models import Response

import threading
import time

def func(num):
    fp = open("night"+str(num)+".txt",mode='a',encoding='utf-8') 
    for i in range(num+1,num+26):
        if i > 436:
            break
        net=requests.get('http://www.maydayfans.com/9478/read_'+str(i)+'.html')

        books = net.text
        books = re.sub(r'\n',r'',books)
        x = re.findall(r'<article>(.*)</article>',books,re.MULTILINE)
        x = re.sub(r'<br/><br/>\u3000\u3000',r"",x[0]) 
        x = re.sub(r"<div class=(.*)script>",r"",x)
        x= re.sub(r's..book(.*)</div>',r"",x)
        fp.write("第"+str(i)+"章")
        fp.write(x)
        print(i)
    fp.close()

for i in range(0,18):
    t = threading.Thread(target=func, args=(i*25,))  # 注意传入的参数一定是一个元组!
    t.start()
